﻿@model BlogPostListModel
@using SmartStore.Web.Models.Blogs;
@using SmartStore.Web.Framework.UI;
@using System.Globalization;

@{
    Layout = "_Layout";

    var parsedMonth = Model.PagingFilteringContext.GetParsedMonth();

    Html.AddTitleParts(
        parsedMonth != null ?
        T("PageTitle.Blog.Month").Text.FormatWith(parsedMonth.Value.ToNativeString("MMMM", CultureInfo.InvariantCulture) + " " + parsedMonth.Value.Year) :
        T("PageTitle.Blog.Tag").Text.FormatWith(Model.PagingFilteringContext.Tag)
    );
    Html.AddMetaDescriptionParts(
        parsedMonth != null ?
        T("Metadesc.Blog.Month").Text.FormatWith(parsedMonth.Value.ToNativeString("MMMM", CultureInfo.InvariantCulture) + " " + parsedMonth.Value.Year) :
        T("Metadesc.Blog.Tag").Text.FormatWith(Model.PagingFilteringContext.Tag)
    );

    Html.AppendScriptParts(true, "~/Content/vendors/imagesloaded/imagesloaded.pkgd.min.js");
}

@section right {
    @{
        Html.RenderAction("BlogMonths", "Blog");
        Html.RenderAction("BlogTags", "Blog");

        <div class="d-none d-lg-block">
            @{ Html.RenderAction("PollBlock", "Poll", new { systemKeyword = "Blog" }); }
        </div>
    }
}

<div class="page blog-page">

    @{ Html.RenderPartial("BlogSummaryHeading", Model); }

    <div class="page-body">

        @{ Html.RenderWidget("bloglist_page_before_posts"); }

        <div class="blogposts mb-4" style="visibility: hidden;">
            @{ Html.RenderPartial("BlogSummaryList", Model); }
        </div>

        @(Html.SmartStore().Pager(Model.PagingFilteringContext)
                .Name("pagination-bottom")
                .QueryParam("pagenumber")
                .ShowFirst(false)
                .ShowLast(false)
                .Style(PagerStyle.Pagination)
                .MaxPagesToDisplay(6))

        @{ Html.RenderWidget("bloglist_page_after_posts"); }
    </div>
</div>

@helper RenderTags(BlogPostModel item)
{
    if (item.Tags.Count > 0 && item.DisplayTagsInPreview)
    {
        <div class="blogpost-tags-overlay mb-3 mb-md-0 p-2">
            @for (int i = 0, length = item.Tags.Count; i < length; i++)
            {
                var tag = item.Tags[i];
                var tagClasses = "blogpost-tag badge p-1 {0}".FormatWith(item.SectionBg.HasValue() && item.SectionBg.Equals("primary") && !item.HasBgImage ? "badge-secondary" : "badge-primary");

                <a class="@tagClasses" href="@Url.RouteUrl("BlogByTag", new { tag = tag.SeName })">@tag.Name</a>
            }
        </div>
    }
}

@helper RenderComments(BlogPostModel item)
{
    if (item.Comments.AllowComments)
    {
        <div class="comments-overlay">
            <a class="fs-xs m-2 btn btn-secondary btn-circle@(item.Comments.NumberOfComments > 0 ? " vivid" : "")"
                href="@Url.RouteUrl("BlogPost", new { SeName = item.SeName })"
                title="@string.Format(@T("Blog.CommentsLink").Text, item.Comments.NumberOfComments)">
                <span class="blogpost-comments-icon fa fa-comment-alt pr-1"></span>
                <span class="blogpost-comments-count">@item.Comments.NumberOfComments</span>
            </a>
        </div>
    }
}

<script>
    $(function () {
        $(".blogposts").masonaryGrid(".bloglist-item");
    });
</script>